﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
/// <summary>
/// 数塔
/// </summary>
public class DP_NumTower:MonoBehaviour
{
    public int Row;

    public int[] Nums;

    void Start()
    {
        CalculateMax();
    }

    public int CalculateMax()
    {
        int[] maxNum = new int[Nums.Length];
        int index = 1;
        int tempLeftMax = 0;
        int tempRightMax = 0;
        int tempMax = 0;
        int returnMaxNum = 0;
        maxNum[0] = Nums[0];
        for (int i = 1; i < Row; i++)
        {
            for(int j = 0; j < i+1; j++)
            {
                if(j==0  )
                {
                    maxNum[index] = maxNum[index - i] + Nums[index];
                    Debug.Log(index + "  " + (index - i) + "    " + maxNum[index - i]+"           "+ Nums[index]);
                }else if(j == i - 1)
                {
                    maxNum[index] = maxNum[index - i-1] + Nums[index];
                }
                else
                {
                    tempLeftMax = maxNum[index - i]+ Nums[index];
                    tempRightMax= maxNum[index-i-1] + Nums[index];
                    maxNum[index] = tempLeftMax > tempRightMax ? tempLeftMax : tempRightMax;
                }
                Debug.Log("第" + index + "的最大值为" + maxNum[index]);
                index++;

                //if (j % 2 != 0)
                //{
                //    tempLeftMax = maxNum[index-1]+ Nums[2 * (j + 1)] ;
                //    tempRightMax = maxNum[index-1] + Nums[2 * (j + 1) + 1];
                //}
                //else
                //{
                //    tempLeftMax = maxNum[index] + Nums[2 * (j + 1) - 1];
                //    tempRightMax = maxNum[index] + Nums[2 * (j + 1)];
                //}
                //tempMax = tempLeftMax > tempRightMax ? tempLeftMax : tempRightMax;
                //if (tempMax > maxNum[index])
                //{
                //    maxNum[index] = tempMax;
                //}
   
                //index++;
            }
        }
        return 0;

        
    }
}
